<template>
  <ele-modal
    :width="550"
    :visible="visible"
    :confirm-loading="loading"
    :title="'维修处理'"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    :footer="null"
  >
    <a-form
      :label-col="{ md: { span: 5 }, sm: { span: 4 }, xs: { span: 24 } }"
      :wrapper-col="{ md: { span: 17 }, sm: { span: 20 }, xs: { span: 24 } }"
    >
      <a-row :gutter="24">
        <a-col :md="24" :sm="24" :xs="24">
          <a-form-item label="维修地点"  v-bind="validateInfos.repair_type">
            <a-radio-group v-model:value="form.repair_type">
				<a-radio-button value="1">总店</a-radio-button>
				<a-radio-button value="2">门店</a-radio-button>
				<a-radio-button value="3">工厂</a-radio-button>
			  </a-radio-group>
          </a-form-item>
          <a-form-item label="实际维修项目">
            <a-select
              optionFilterProp="label"
              :options="repairOptions"
              allow-clear
              v-model:value="form.real_repair_item_code"
              placeholder="请选择"
              autocomplete="off"
            />
          </a-form-item>
          <a-form-item label="预估维修费用">
            <a-input
              allow-clear
              placeholder="请输入"
              v-model:value="form.repair_evaluate"
              autocomplete="off"
            />
          </a-form-item>
          <a-form-item label="预计完成日期">
            <a-date-picker
              class="ele-fluid"
              valueFormat="YYYY/MM/DD"
              placeholder="请选择"
              v-model:value="form.predict_complete_time"
              autocomplete="off"
            />
          </a-form-item>
          <a-form-item label="备注">
            <a-textarea
              placeholder="请输入"
              v-model:value="form.handle_note"
              autocomplete="off"
            />
          </a-form-item>
        </a-col>
		<a-col :md="24" :sm="24" :xs="24">
			<div class="margin-15" style="float:right">
				<a-space>
					<a-button type="primary" @click="save()">保存</a-button>
					<a-button type="primary">下一步</a-button>
					<a-button>取消</a-button>
				</a-space>
			</div>
        </a-col>
      </a-row>
    </a-form>
  </ele-modal>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { Form, message } from 'ant-design-vue';
  import {get_repair_item_select} from '@/api/material/select';
  // 表格列配置
  const useForm = Form.useForm;

  const emit = defineEmits(['done', 'update:visible']);

  const props = defineProps({
    // 弹窗是否打开
    visible: Boolean,
	order_sn: String
  });

  // 提交状态
  const loading = ref(false);
  const repairOptions = ref([]);
  const checked = ref(true);

  // 表单数据
  const form = reactive({
    order_sn:props.order_sn,
    repair_type:'',
    real_repair_item_code:'',
    repair_evaluate:'',
    predict_complete_time:'',
    handle_note:''
  });
  
  onMounted(() => {
    get_repair_item_select({ page: 1, page_size: 99999 }).then((res) => {
      repairOptions.value = res;
    });
	
  })

  const change = (e) => {
    form.status = e ? '1' : '0';
  };

  // 表单验证规则
  const rules = reactive({
    repair_type: [
      {
        required: true,
        message: '请选择维修地点',
        type: 'string',
        trigger: 'change'
      }
    ]
  });

  const { validate, validateInfos } = useForm(form, rules);

  /* 保存*/
  const save = () => {
    validate()
      .then(() => {
        emit('done', form);
      })
      .catch(() => {});
  };
  /* 更新visible */
  const updateVisible = (value) => {
    emit('update:visible', value);
  };
</script>
<style scoped></style>
